﻿package mortal.game.view.guild.otherpanel
{
    import Message.Game.*;
    import __AS3__.vec.*;
    import com.mui.controls.*;
    import com.mui.display.*;
    import extend.language.*;
    import fl.data.*;
    import flash.events.*;
    import flash.text.*;
    import mortal.common.*;
    import mortal.common.global.*;
    import mortal.component.gconst.*;
    import mortal.game.cache.*;
    import mortal.game.cache.guild.module.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.pageSelect.*;
    import mortal.game.view.guild.cellrender.*;
    import mortal.mvc.core.*;
    import mortal.mvc.interfaces.*;

    public class GuildWareHouseRecordPanel extends GuildOtherBasePanel
    {
        private var _topContianer:GSprite;
        private var _regionTitleBg:ScaleBitmap;
        private var _txtDate:GTextFiled;
        private var _txtOprName:GTextFiled;
        private var _txtDealName:GTextFiled;
        private var _txtItemName:GTextFiled;
        private var _comboBox:GComboBox;
        private var _list:GTileList;
        private var _pageSelecter:PageSelecter;
        private static var _instance:GuildWareHouseRecordPanel;

        public function GuildWareHouseRecordPanel(param1:ILayer = null)
        {
            setSize(504, 355);
            super(param1);
            if (_instance)
            {
                throw new Error("单例模式");
            }
            title = "" + Language.getString(71245);
            return;
        }// end function

        override public function layoutUI() : void
        {
            super.layoutUI();
            var _loc_1:* = GlobalStyle.textFormatBai;
            _loc_1.align = TextFormatAlign.CENTER;
            this._topContianer = UIFactory.getUICompoment(GSprite, 9, 32, this);
            this._regionTitleBg = UIFactory.bg(4, 0, 480, 28, this._topContianer, ImagesConst.RegionTitleBg);
            this._txtDate = UIFactory.textField("" + Language.getString(71246), 10, 3, 85, 22, this._topContianer, _loc_1);
            this._txtOprName = UIFactory.textField("" + Language.getString(71247), 105, 3, 95, 22, this._topContianer, _loc_1);
            this._txtDealName = UIFactory.textField("" + Language.getString(71248), 200, 3, 95, 22, this._topContianer, _loc_1);
            this._txtItemName = UIFactory.textField("" + Language.getString(71249), 300, 3, 95, 22, this._topContianer, _loc_1);
            var _loc_2:* = new DataProvider([{index:0, type:0, label:Language.getString(71250), value:-1}, {index:1, type:1, label:"" + Language.getString(71251), value:EGuildWarehouseOper._EGuildWarehouseIn}, {index:2, type:2, label:"" + Language.getString(71252), value:EGuildWarehouseOper._EGuildWarehouseApplyAgree}, {index:3, type:3, label:"" + Language.getString(71253), value:EGuildWarehouseOper._EGuildWarehouseOut}, {index:4, type:4, label:"" + Language.getString(71254), value:EGuildWarehouseOper._EGuildWarehouseAllocation}]);
            this._comboBox = UIFactory.gComboBox(423, 3, 58, 22, _loc_2, this._topContianer);
            this._comboBox.configEventListener(Event.CHANGE, this.onComboBoxChange);
            pushUIToDisposeVec(this._regionTitleBg);
            pushUIToDisposeVec(this._txtDate);
            pushUIToDisposeVec(this._txtOprName);
            pushUIToDisposeVec(this._txtDealName);
            pushUIToDisposeVec(this._txtItemName);
            pushUIToDisposeVec(this._comboBox);
            this._pageSelecter = UIFactory.pageSelecter(195, 323, this, PageSelecter.CompleteMode);
            this._pageSelecter.setbgStlye(ImagesConst.ComboBg, new GTextFormat());
            this._pageSelecter.maxPage = 1;
            this._pageSelecter.pageTextBoxSize = 36;
            this._pageSelecter.configEventListener(Event.CHANGE, this.onPageChange);
            this._list = UIFactory.tileList(19, 60, 450, 230, this);
            this._list.rowHeight = 32;
            this._list.columnWidth = 480;
            this._list.rowCount = 8;
            this._list.columnCount = 1;
            this._list.setStyle("cellRenderer", GuildWareHouseRecListRenderer);
            Dispatcher.dispatchEvent(new DataEvent(EventName.Guild_wareHouse_getRecords));
            return;
        }// end function

        private function updataList() : void
        {
            var _loc_3:Vector.<SGuildWarehouseRecord> = null;
            var _loc_1:* = new DataProvider();
            var _loc_2:* = Cache.instance.guild.selfGuildInfo.wareHouse;
            switch(this._comboBox.selectedItem.index)
            {
                case EGuildWarehouseOper._EGuildWarehouseIn:
                {
                    _loc_3 = _loc_2.recordVec;
                    break;
                }
                case EGuildWarehouseOper._EGuildWarehouseOut:
                case EGuildWarehouseOper._EGuildWarehouseApplyAgree:
                case EGuildWarehouseOper._EGuildWarehouseApplyRefuse:
                case EGuildWarehouseOper._EGuildWarehouseAllocation:
                {
                    _loc_3 = _loc_2.recordVec.filter(this.isComboSelectValue);
                    break;
                }
                default:
                {
                    break;
                }
            }
            var _loc_4:* = this._list.rowCount * this._list.columnCount;
            var _loc_5:* = (this._pageSelecter.currentPage - 1) * _loc_4;
            var _loc_6:* = _loc_5 + _loc_4;
            var _loc_7:* = _loc_5;
            while (_loc_7 < _loc_6)
            {
                
                if (_loc_7 < _loc_3.length)
                {
                    _loc_1.addItem(_loc_3[_loc_7]);
                }
                _loc_7++;
            }
            this._list.dataProvider = _loc_1;
            this._list.drawNow();
            var _loc_8:* = _loc_3.length;
            this._pageSelecter.maxPage = Math.ceil(_loc_8 / (this._list.rowCount * this._list.columnCount));
            return;
        }// end function

        private function onComboBoxChange(event:Event) : void
        {
            this._pageSelecter.currentPage = 1;
            this.updataList();
            return;
        }// end function

        private function onPageChange(event:Event) : void
        {
            this.updataList();
            return;
        }// end function

        override public function onMouseClick(event:MouseEvent) : void
        {
            super.onMouseClick(event);
            return;
        }// end function

        override public function update() : void
        {
            super.update();
            if (this.isHide)
            {
                return;
            }
            this.updataList();
            return;
        }// end function

        override protected function setWindowCenter() : void
        {
            _windowCenter = ResourceConst.getScaleBitmap(ImagesConst.PanelBg);
            return;
        }// end function

        public function isComboSelectValue(param1:SGuildWarehouseRecord, param2:int, param3:Vector.<SGuildWarehouseRecord>) : Boolean
        {
            var _loc_4:* = this._comboBox.selectedItem.value;
            return param1.oper.value() == _loc_4;
        }// end function

        public static function get instance() : GuildWareHouseRecordPanel
        {
            if (_instance == null)
            {
                _instance = new GuildWareHouseRecordPanel;
            }
            return _instance;
        }// end function

        public static function hasInstance() : Boolean
        {
            return _instance != null;
        }// end function

    }
}
